package com.mathdroid.model.abilities;

import java.util.LinkedList;

import com.mathdroid.model.EModelObserverEvent;
import com.mathdroid.model.Model;

/**
 * An ability template is a list of abilities. The lowest index is the ability
 * which has the highest priority. The hightest index has the lowest priority.
 */
public class AbilityTemplate extends LinkedList<Ability> {

	/**
	 * Generated UID.
	 */
	private static final long serialVersionUID = 4635801626786411597L;
	
	/**
	 * The name of this template.
	 */
	private String templateName = "Unnamed";
	
	/**
	 * Set the name of this template.
	 * @param n Name.
	 */
	public final void setName(final String n) {
		this.templateName = n;
	}
	
	@Override
	public final String toString() {
		return this.templateName;
	}

	/**
	 * Swap two abilities. Their priority swaps.
	 * @param j First index.
	 * @param k Second index.
	 */
	public final void swap(final int j, final int k) {
		if (j >= 0 && j < this.size() 
				&& k >= 0 && k < this.size()) {
			
			Ability a = this.get(j);
			Ability b = this.get(k);
			
			this.set(j, b);
			this.set(k, a);
			
			Model.fireEvent(EModelObserverEvent.ABILITIES_CHANGED);
		}
	}
}
